package com.ycode.bang.anbang.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.ycode.bang.anbang.MyApp;
import com.ycode.bang.anbang.R;
import com.ycode.bang.anbang.baseui.BaseActivity;

import butterknife.ButterKnife;
import butterknife.InjectView;
/**
 * Created by maosongsong on 2016/4/5.
 */
public class HomepageActivity extends BaseActivity implements View.OnClickListener {
    @InjectView(R.id.title)
    TextView title;
    @InjectView(R.id.back)
    ImageView back;

    @InjectView(R.id.lin_one)
    LinearLayout mLinOne;
    @InjectView(R.id.lin_two)
    LinearLayout mLinTwo;
    @InjectView(R.id.lin_three)
    LinearLayout mLinThree;
    @InjectView(R.id.kuaidishoufa)
    LinearLayout kuaidishoufa;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_homepage);
        ButterKnife.inject(this);
        initView();
    }

    public void initView() {
        back.setVisibility(View.GONE);
        title.setText("慧盟管家");
        mLinOne.setOnClickListener(this);
        mLinTwo.setOnClickListener(this);
        mLinThree.setOnClickListener(this);
        kuaidishoufa.setOnClickListener(this);
    }

    @Override
    protected void getSuccessRequest(Object response, int flag) {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.lin_one:
                Intent intentone = new Intent(this, AcceptOrderActivity.class);
                startActivity(intentone);
                break;
            case R.id.lin_two:
                Intent intenttwo = new Intent(this, CreateOrder.class);
                startActivity(intenttwo);
                break;
            case R.id.lin_three:

                MyApp.instance.homepageActivity=HomepageActivity.this;
                Intent intentthree = new Intent(this, PersonalCenterActivity.class);
                startActivity(intentthree);
                break;
            case R.id.kuaidishoufa:
                Intent kuaidishoufa = new Intent(this, ExpressMainActivity.class);
                startActivity(kuaidishoufa);
                break;
        }
    }
    /**
     * 退出应用
     */
    private long firstime = 0;

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // TODO Auto-generated method stub
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
            long secondtime = System.currentTimeMillis();
            if (secondtime - firstime > 3000) {
                Toast.makeText(baseContext, "再按一次返回键退出", Toast.LENGTH_SHORT)
                        .show();
                firstime = System.currentTimeMillis();
                return true;
            } else {
                MyApp.instance.exit();
            }
        }
        return super.onKeyDown(keyCode, event);
    }
}
